home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 12 / CU Amiga Magazine's Super CD-ROM 12 (1997)(EMAP Images)(GB)[!][issue 1997-07].iso / CUCD / Games / DestructivePoker / sources / sources.lha / double.cpp < prev    next >
C/C++ Source or Header  |  1997-02-20  |  5KB  |  189 lines

  1. /*
  2.         double.cpp
  3.  
  4.         V1.00 - 241196  Kimmo Teräväinen
  5.         -----   ------  ----------------
  6.         Look double.h
  7.  
  8. */
  9.  
  10. #include "double.h"
  11.  
  12. #ifdef _Windows
  13.  
  14. DEFINE_RESPONSE_TABLE1(TDoubleDialog,TDialog)
  15.   EV_BN_CLICKED(BUTTON_SMALL ,ButtonSmall),
  16.   EV_BN_CLICKED(BUTTON_BIG   ,ButtonBig),
  17.   EV_BN_CLICKED(IDCANCEL     ,ButtonOK),
  18.   EV_BN_CLICKED(IDOK         ,ButtonOK),
  19. END_RESPONSE_TABLE;
  20.  
  21. void TDoubleDialog::SetupWindow()
  22. {
  23.   TDialog::SetupWindow();
  24.   CreateCard();
  25. }
  26.  
  27. #else
  28. #include <inline++/exec.h>
  29. #include <stdio.h>
  30. #include "requester.h"
  31.  
  32. #include "pokergadgets.h"
  33.  
  34. extern TextFont *TEXTFONT;
  35. extern UBYTE pens[];
  36. extern UBYTE gfxpens[256];
  37.  
  38. const cButton cDoubleGadgets::DoubleButtons[] = {
  39.   cButton(GADGET_OK    , 50,149,100,14,"Don´t Double"),
  40.   cButton(GADGET_SMALL , 40,130, 50,14,"_Small"),
  41.   cButton(GADGET_BIG   ,110,130, 50,14,"_Big"),
  42.   cButton(0,0,0,0,0,NULL)
  43. };
  44.  
  45.  
  46. void TDoubleDialog::Execute()
  47. {
  48.   Window *Wnd=NULL;
  49.   int BTop = parent->WScreen->WBorTop + (parent->WScreen->Font->ta_YSize + 1);
  50.  
  51.   {
  52.     struct TagItem window_tags[] = {
  53.       { WA_Title, (long unsigned)"Double" },
  54.       { WA_DragBar , TRUE},
  55.       { WA_DepthGadget , TRUE},
  56.       { WA_CloseGadget, TRUE },
  57.       { WA_Left, 200+parent->LeftEdge }, { WA_Top, 40+parent->TopEdge },
  58.       { WA_Width, 200 }, { WA_Height, 170+BTop },
  59.       { WA_CustomScreen, (ULONG)parent->WScreen },
  60.       { WA_Activate, TRUE},
  61.       { WA_IDCMP, IDCMP_VANILLAKEY |
  62.                   IDCMP_MOUSEBUTTONS |
  63.                   IDCMP_GADGETUP |
  64.                   IDCMP_REFRESHWINDOW |
  65.                   IDCMP_CLOSEWINDOW },
  66.       { TAG_DONE, NULL}
  67.     };
  68.     Wnd=OpenWindowTagList(NULL,window_tags);
  69.   }
  70.  
  71.   if(Wnd)
  72.   {
  73.       SetFont(Wnd->RPort,TEXTFONT);
  74.       SetABPenDrMd(Wnd->RPort,gfxpens[0],gfxpens[0],JAM1);
  75.       RectFill(Wnd->RPort,Wnd->BorderLeft,Wnd->BorderTop,
  76.                           Wnd->Width-Wnd->BorderRight,
  77.                           Wnd->Height-Wnd->BorderBottom);
  78.  
  79.       int RT,terminated=FALSE;
  80.       cDoubleGadgets doublegads(Wnd,game,win);
  81.  
  82.  
  83.       Move(Wnd->RPort,
  84.            (Wnd->Width-TextLength(Wnd->RPort,(UBYTE*)"Small or Big Card?",18))/2,
  85.            20+Wnd->BorderTop);
  86.       SetAPen(Wnd->RPort,pens[1]); SetDrMd(Wnd->RPort,JAM1);  // Text
  87.       Text(Wnd->RPort,(UBYTE*)"Small or Big Card?",18); //
  88.  
  89.       RefreshWindowFrame(Wnd);
  90.  
  91.       while(!terminated) {
  92.         Message *msg;
  93.  
  94.         WaitPort(Wnd->UserPort);
  95.         while(msg=GetMsg(Wnd->UserPort)) {
  96.  
  97.           if((RT=doublegads.IDCMP((const IntuiMessage *)msg))==IDCMP_NOT_DONE)
  98.             switch(((IntuiMessage *)msg)->Class) {
  99.               case IDCMP_CLOSEWINDOW: terminated=TRUE; break;
  100.             }
  101.           if(RT==IDCMP_TERMINATED) terminated=TRUE;
  102.           if(RT!=IDCMP_REPLYED) ReplyMsg(msg);
  103.         }
  104.       }
  105.  
  106.     CloseWindow(Wnd);
  107.   }
  108. }
  109.  
  110.  
  111.  
  112. int cDoubleGadgets::GadgetSmall()
  113. {
  114.   if(!card) return IDCMP_TERMINATED;
  115.   card->Turn_CoverUp();
  116.  
  117.   if(card->Num()<6 || card->Suit()==JOKER) {
  118.     char buffer[40];
  119.     win+=win;
  120.     sprintf(buffer,"Win Pot Doubled! Pot=%ld",(ULONG)win);
  121.     cRequester(wnd,"Double Small",buffer).Execute();
  122.     CreateCard();
  123.     return IDCMP_DONE;
  124.   }
  125.   cRequester(wnd,"Double Small","Win Pot lost!").Execute();
  126.  
  127.   return IDCMP_TERMINATED;
  128. }
  129.  
  130.  
  131. int cDoubleGadgets::GadgetBig()
  132. {
  133.   if(!card) return IDCMP_TERMINATED;
  134.   card->Turn_CoverUp();
  135.  
  136.   if(card->Num()>6 || card->Suit()==JOKER) {
  137.     char buffer[40];
  138.     win+=win;
  139.     sprintf(buffer,"Win Pot Doubled! Pot=%ld",(ULONG)win);
  140.     cRequester(wnd,"Double Big",buffer).Execute();
  141.     CreateCard();
  142.     return IDCMP_DONE;
  143.   }
  144.   cRequester(wnd,"Double Big","Win Pot lost!").Execute();
  145.  
  146.   return IDCMP_TERMINATED;
  147. }
  148.  
  149.  
  150.  
  151. int cDoubleGadgets::IDCMP(const IntuiMessage *msg)
  152. {
  153.   switch(msg->Class) {
  154.     case IDCMP_REFRESHWINDOW:
  155.          GT_BeginRefresh(wnd);
  156.          GT_EndRefresh(wnd, TRUE);
  157.          return IDCMP_DONE;
  158.  
  159.     case IDCMP_VANILLAKEY:
  160.          switch(msg->Code) {
  161.            case 10:
  162.            case 13:  game->Money_Add(win);
  163.            case 27:  return IDCMP_TERMINATED;
  164.            case 's':
  165.            case 'S': return GadgetSmall();
  166.            case 'b':
  167.            case 'B': return GadgetBig();
  168.          }
  169.          break;
  170.     case IDCMP_GADGETUP:
  171.          {
  172.            Gadget *gad = (struct Gadget *)msg->IAddress;
  173.            switch(gad->GadgetID) {
  174.              case GADGET_SMALL:  return GadgetSmall();
  175.              case GADGET_BIG:    return GadgetBig();
  176.              case GADGET_OK:     game->Money_Add(win);
  177.                                  return IDCMP_TERMINATED;
  178.            }
  179.            return IDCMP_DONE;
  180.          }
  181.     case IDCMP_CLOSEWINDOW:
  182.          game->Money_Add(win);
  183.          return IDCMP_TERMINATED;
  184.   }
  185.   return IDCMP_NOT_DONE;
  186. }
  187.  
  188. #endif
  189.